<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<style>
  h1{color: red;}
  form{border: 1px solid ; padding: 20px;}
</style>
<body>
<h1>欢迎进行登录界面</h1>
<form action="login" name ="myform" method="post" onsubmit="return checkAll()">
  账 号:<input type="text" name="username" onblur="checkUsername()"><br><br><br>
  密 码:<input type="password" name="upasswd" onblur="checkPasswd()"><br><br>
  <input type="submit" value="提交"> <a href="/regist.html">注册用户</a>
</form>
</body>
<script>
  function checkUsername(){
    var username = document.myform.username;
    if(username.match(/\w{8,16}/)==null){ //可以写成/[0-9A-Za-z_]{8,16}/
      alert("请输入8-16位的账号");
      return false;
    }  else{
      return true;
    }
  }
  function checkPasswd(){
      var passwd = document.myform.passwd;
      if(passwd == null){
      alert("密码为空")
      return false;
    }else{
      if(passwd.match(/\w{8,16}/)==null){ //可以写成/[0-9A-Za-z_]{8,16}/
        alert("请输入8-16位的密码");
        return false;
      }else{
        return true;
      }
    }
  }

  function checkAll(){
    return checkUsername() && checkPasswd();
  }

</script>
</html>